DEFINITION MODULE M2DM; (* NW 23.3.85; WH 22.5.85 / 9.1.86  *)
                        (* HS 19.4.85 / 31.5.86 / 19.12.91 *)

  FROM SYSTEM IMPORT ADDRESS;

  CONST   WordSize   =     16;
          MaxChar    =   377C;
          MaxCard    =  65535;
          MinInt     = -32767 - 1;
          MaxInt     =  32767;
          MinDouble  =  80000000H;
          MaxDouble  =  7FFFFFFFH;
          NilVal     =     0D;

  TYPE    ObjPtr     = POINTER TO Object;
          StrPtr     = POINTER TO Structure;
          ParPtr     = POINTER TO Parameter;
          PDPtr      = POINTER TO PDesc;
          KeyPtr     = POINTER TO Key;

          ObjClass   = (Header, Const, Typ, Var, Field, Proc, Code, Module, Temp);

          (* Note:   for scalar types:     form <= Double        *)
          (*         for subrange types:   RBaseTyp^.form < form *)
          (*         for structured types: form > Opaque         *)
          StrForm  = (Undef, Bool, Char, Card, CardInt, Int, Enum, LCard, Double,
                      Range, Real, LongReal, Pointer, Set, ProcTyp, Opaque,
                      String, Array, Record);

          (* Note:   basic standard procedures :   Abs  .. Val    *)
          (*         supplementary procedures  :   XAsh .. Round  *)
          Standard   = (Abs, Adr, Cap, Chr, Dec, Excl, Float, FloatD, Halt,
                        High, Inc, Incl, Inline, Long, Max, Min, Odd, Ord,
                        Reg, Setreg, Shift, Short, Size, Tsize, Trunc, TruncD, Val,
                        XAsh, XLsh, XRot, XMsk, XCom, Sqrt, Entier, Round, NonStand);

          ConstValue = RECORD
                         CASE :StrForm OF
                           Undef:               U:  LONGINT;
                         | Bool:                B:  BOOLEAN;
                         | Char, Enum:          Ch: CHAR;
                                             prev:  ObjPtr;
                         | Card, CardInt:       C:  CARDINAL;
                         | Int:                 I:  INTEGER;
                         | LCard, Double:       D:  LONGINT;
                         | Real:                R:  REAL;
                         | Set:                 S:  BITSET;
                         | String:  D0, D1, D2, D3: INTEGER;
                         | LongReal:            X:  LONGREAL;
                         (* M2RM assumes correct overlaying of X *)
                         (* with the fields D0, D1, D2 and D3.   *)
                         END;
                       END;

          PDesc      = RECORD
                         forward, exp: BOOLEAN;
                         num, lev, adr, size, endAdr: INTEGER;
                       END;

          Object     = RECORD
                         name:     INTEGER;  (* index to name buffer *)
                         typ:      StrPtr;
                         left,
                         right,
                         next:     ObjPtr;
                         exported: BOOLEAN;
                         CASE class: ObjClass OF
                           Header: kind:       ObjClass;  (* Typ, Proc, Module *)
                                   last, heap: ObjPtr;
                                   withadr:    INTEGER;
                         | Const:  conval:     ConstValue;
                         | Typ:    mod:        ObjPtr;
                         | Var:    varpar:     BOOLEAN;
                                   vmod, vlev,
                                   vadr:       INTEGER;
                         | Field:  offset:     INTEGER;
                         | Proc:   pd:         PDPtr;
                                   firstParam: ParPtr;
                                   firstLocal: ObjPtr;
                                   pmod:       INTEGER;
                         | Code:   cd:         PDPtr;
                                   firstArg:   ParPtr;
                                   std:        Standard;
                                   cnum:       CARDINAL;
                         | Module: key:        KeyPtr;
                                   firstObj,
                                   root:       ObjPtr;
                                   modno:      INTEGER;
                         | Temp:   baseref:    INTEGER;
                         END;
                       END;

          Structure  = RECORD
                         strobj: ObjPtr;  (* object (type) naming structure *)
                         size, ref: INTEGER;
                         CASE form: StrForm OF
                         | Undef, Bool, Char, Card, CardInt, Int,
                           LCard, Double, Real, LongReal, String:
                         | Enum:    ConstLink: ObjPtr;
                                    NofConst:  INTEGER;
                         | Range:   RBaseTyp:  StrPtr;
                                    min, max,
                                    BndAdr:    INTEGER;
                         | Pointer: PBaseTyp:  StrPtr;
                                    BaseId:    INTEGER;  (* forward refs *)
                         | Set:     SBaseTyp:  StrPtr;
                         | Array:   ElemTyp,
                                    IndexTyp:  StrPtr;
                                    dyn:       BOOLEAN;
                         | Record:  firstFld:  ObjPtr;
                         | ProcTyp: firstPar:  ParPtr;
                                    resTyp:    StrPtr;
                         | Opaque:  (* no field *)
                         END;
                       END;

          Parameter  = RECORD
                         name: INTEGER; varpar: BOOLEAN; typ: StrPtr; next: ParPtr;
                       END;
          Key        = RECORD k0, k1, k2: INTEGER END;

  VAR     mainmod, sysmod: ObjPtr;
          notyp, undftyp, booltyp, chartyp, cardtyp, cardinttyp, inttyp,
          bitstyp, lcardtyp, dbltyp, realtyp, lrltyp, proctyp, stringtyp,
          addrtyp, wordtyp, bytetyp: StrPtr;
          rngchk    : BOOLEAN;
          ovflchk   : BOOLEAN;

  PROCEDURE ALLOCATE(VAR a: ADDRESS; n: CARDINAL);
  PROCEDURE Available(): CARDINAL;
  PROCEDURE ResetHeap(a: ADDRESS);

END M2DM. (* Copyright Departement Informatik, ETH Zuerich, Switzerland, 1992 *)
